namespace MIMSDomain.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class FamilyandDrugHistory : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.FamilyHistories",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        IllnessInTheFamily = c.Boolean(),
                        HasGallstones = c.Boolean(),
                        HasEpilepsy = c.Boolean(),
                        HasHighBloodPressure = c.Boolean(),
                        FamilyTree_Id = c.Int(),
                        Patient_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.FamilyTrees", t => t.FamilyTree_Id)
                .ForeignKey("dbo.Patients", t => t.Patient_Id)
                .Index(t => t.FamilyTree_Id)
                .Index(t => t.Patient_Id);
            
            CreateTable(
                "dbo.FamilyTrees",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        MajorIllness = c.String(),
                        Cause = c.String(),
                        AgeOfDeath = c.Int(nullable: false),
                        Patient_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Patients", t => t.Patient_Id)
                .Index(t => t.Patient_Id);
            
            CreateTable(
                "dbo.DrugHistories",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        HasMedications = c.Boolean(),
                        MedicationsPrescribed = c.Boolean(),
                        MedicationsPurchased = c.Boolean(),
                        UsesInhalers = c.Boolean(),
                        UsesSkinCreams = c.Boolean(),
                        UsesPatches = c.Boolean(),
                        UsesSuppositories = c.Boolean(),
                        UsesTabletsToSuck = c.Boolean(),
                        HasStoppedTakenMedication = c.Boolean(),
                        TakesMedicationPrescribedForOtherPeople = c.Boolean(),
                        UsesHerbalOrOtherComplementaryMedicines = c.Boolean(),
                        Patient_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Patients", t => t.Patient_Id)
                .Index(t => t.Patient_Id);
            
            AddColumn("dbo.SurgicalHistories", "Patient_Id", c => c.Int());
            AddColumn("dbo.ObstetricHistories", "Patient_Id", c => c.Int());
            AlterColumn("dbo.ObstetricHistories", "Id", c => c.Int(nullable: false, identity: true));
            DropPrimaryKey("dbo.ObstetricHistories", new[] { "id" });
            AddPrimaryKey("dbo.ObstetricHistories", "Id");
            AddForeignKey("dbo.SurgicalHistories", "Patient_Id", "dbo.Patients", "Id");
            AddForeignKey("dbo.ObstetricHistories", "Patient_Id", "dbo.Patients", "Id");
            CreateIndex("dbo.SurgicalHistories", "Patient_Id");
            CreateIndex("dbo.ObstetricHistories", "Patient_Id");
        }
        
        public override void Down()
        {
            DropIndex("dbo.ObstetricHistories", new[] { "Patient_Id" });
            DropIndex("dbo.DrugHistories", new[] { "Patient_Id" });
            DropIndex("dbo.FamilyTrees", new[] { "Patient_Id" });
            DropIndex("dbo.FamilyHistories", new[] { "Patient_Id" });
            DropIndex("dbo.FamilyHistories", new[] { "FamilyTree_Id" });
            DropIndex("dbo.SurgicalHistories", new[] { "Patient_Id" });
            DropForeignKey("dbo.ObstetricHistories", "Patient_Id", "dbo.Patients");
            DropForeignKey("dbo.DrugHistories", "Patient_Id", "dbo.Patients");
            DropForeignKey("dbo.FamilyTrees", "Patient_Id", "dbo.Patients");
            DropForeignKey("dbo.FamilyHistories", "Patient_Id", "dbo.Patients");
            DropForeignKey("dbo.FamilyHistories", "FamilyTree_Id", "dbo.FamilyTrees");
            DropForeignKey("dbo.SurgicalHistories", "Patient_Id", "dbo.Patients");
            DropPrimaryKey("dbo.ObstetricHistories", new[] { "Id" });
            AddPrimaryKey("dbo.ObstetricHistories", "id");
            AlterColumn("dbo.ObstetricHistories", "id", c => c.Int(nullable: false, identity: true));
            DropColumn("dbo.ObstetricHistories", "Patient_Id");
            DropColumn("dbo.SurgicalHistories", "Patient_Id");
            DropTable("dbo.DrugHistories");
            DropTable("dbo.FamilyTrees");
            DropTable("dbo.FamilyHistories");
        }
    }
}
